import type { GlobalGuessInstance } from '@/types/components'
import { ref } from 'vue'

/**
 * 猜你喜欢组合式函数
 */
export const useGuessList = () => {
  // 获取猜你喜欢组件实例
  const guessRef = ref<GlobalGuessInstance>()

  // 滚动触底事件
  const onScrolltolower = () => {
    guessRef.value?.getMore()
  }

  // 返回 ref 和事件处理函数
  return {
    guessRef,
    onScrolltolower,
  }
}

/**
 * 获取地址列表组合式函数
 */
import type { AddressItem } from '@/types/address'
import { getMemberAddressAPI } from '@/services/address'
export const useAddressList = () => {
  // 获取收货地址列表数据
  const addressList = ref<AddressItem[]>([])
  const getMemberAddressData = async () => {
    const res = await getMemberAddressAPI()
    addressList.value = res.result
  }

  // 返回 ref 和事件处理函数
  return {
    addressList,
    getMemberAddressData,
  }
}
